package test_20220902;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-09-02
 * Time: 13:01
 */
class MyArray{
    public int[] array;
    private int index;

    public MyArray(int n){
        this.array = new int[n];
        this.index = 0;
    }

    public void add(int val){
        array[index++] = val;
    }

    public void find(int val){
        for(int i = 0; i < index; i++){
            if(array[i] == val){
                System.out.println("找到这个元素,下标为:" + i);
                return;
            }
        }
        System.out.println("数组中没有此元素");
    }
}

public class Demo1 {
    public static void main(String[] args) {
        MyArray myArray = new MyArray(10);
        myArray.add(32);
        myArray.add(11);
        myArray.add(48);
        myArray.add(88);
        myArray.find(48);
    }
}
